﻿
/*
NAILSUPERSTORE ® COMPANY
 
[HISTORY]
Created By  	: NGUYEN VAN TY
Created Date	: 12/10/2010
Modified By     :
Modified Date   :
Note            :

*/

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using CommonTagTime;
using CommonTagTime.ModelObject;
using CommonTagTime.Business;
namespace CommonTagTime.DataAccess
{
    public class daoProductRelated
    {
        public daoProductRelated()
        {

        }           
        public bool Delete(ProductRelated objProduct)
        {
            int result = 0;
            clsSQL clsSQL = new clsSQL();
            SqlParameter[] para = new SqlParameter[2];         
            try
            {
                para[0] = new SqlParameter(busProductRelated.PRODUCTID, SqlDbType.Int);
                para[0].Value = objProduct.ProductID;
                para[1] = new SqlParameter(busProductRelated.PPRODUCTRELATEDID, SqlDbType.Int);
                para[1].Value = objProduct.ProductRelatedID;
                result = clsSQL.SPExecute("ProductRelated_Delete", para); 
            }
            catch (Exception ex)
            {
                clsFile.WriteLog("daoProductRelated", "Delete(ProductRelated objProduct)", ex.ToString());
            }
            finally
            {
                clsSQL.Dispose();
                clsSQL = null;
            }

            if (result > 0)
                return true;
            return false;
        }      
        public int Insert(ProductRelated objProduct)
        {
            int result = 0;
            clsSQL clsSQL = new clsSQL();
            SqlParameter[] para = new SqlParameter[2];
            Product item = new Product();
            try
            {
                para[0] = new SqlParameter(busProductRelated.SKUPPRODUCTRELATEDID, SqlDbType.NVarChar);
                para[0].Value = clsConvert.StringToDB(objProduct.SKU);
                para[1] = new SqlParameter(busProductRelated.PRODUCTID, SqlDbType.Int);
                para[1].Value = objProduct.ProductID;
                result = clsSQL.SPExecute("ProductRelated_Insert", para);
                
            }
            catch (Exception ex)
            {
                item = null;
                clsFile.WriteLog("daoProductRelated", "Insert(ProductRelated)", ex.ToString());
            }
            finally
            {
                clsSQL.Dispose();
                clsSQL = null;
            }
            return result;
        }
        public bool OrderDown(ProductRelated objProduct)
        {
            int result = 0;
            clsSQL clsSQL = new clsSQL();
            SqlParameter[] para = new SqlParameter[2];
            try
            {
                para[0] = new SqlParameter(busProductRelated.PPRODUCTRELATEDID, SqlDbType.Int);
                para[0].Value = objProduct.ProductRelatedID;
                para[1] = new SqlParameter(busProductRelated.PRODUCTID, SqlDbType.Int);
                para[1].Value = objProduct.ProductID;
                result = clsSQL.SPExecute("ProductRelated_OrderDown", para);

            }
            catch (Exception ex)
            {
                clsFile.WriteLog("daoProductRelated", "ProductRelated(ProductRelated objProduct)", ex.ToString());
            }
            finally
            {
                clsSQL.Dispose();
                clsSQL = null;
            }
            if (result > 0)
                return true;
            return false;
        }
        public bool OrderUp(ProductRelated objProduct)
        {
            int result = 0;
            clsSQL clsSQL = new clsSQL();
            SqlParameter[] para = new SqlParameter[2];
            try
            {
                para[0] = new SqlParameter(busProductRelated.PPRODUCTRELATEDID, SqlDbType.Int);
                para[0].Value = objProduct.ProductRelatedID;
                para[1] = new SqlParameter(busProductRelated.PRODUCTID, SqlDbType.Int);
                para[1].Value = objProduct.ProductID;
                result = clsSQL.SPExecute("ProductRelated_OrderUp", para);

            }
            catch (Exception ex)
            {
                clsFile.WriteLog("daoProductRelated", "OrderUp(ProductRelated objProduct)", ex.ToString());
            }
            finally
            {
                clsSQL.Dispose();
                clsSQL = null;
            }
            if (result > 0)
                return true;
            return false;
        }
        
    }
}

